package h0809;

import java.util.Arrays;
import java.util.Scanner;

/**
  * @description 反射计数
  * @author 不知名帅哥
  * @date 2024/8/9 14:09
  * @version 1.0
*/
public class ReflectionCounting {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt(); //宽
        int h = sc.nextInt(); //高
        int x = sc.nextInt();  //起始位置列
        int y = sc.nextInt();  //起始位置行
        int sx = sc.nextInt(); //速度sx
        int sy = sc.nextInt();  //速度sy
        int t = sc.nextInt();  //时间t
        sc.nextLine();
        int[][] arr = new int[h][w];
        for (int i = 0; i < h; i++) {
            arr[i] = Arrays.stream(sc.nextLine().split("")).mapToInt(Integer::parseInt).toArray();
        }
        System.out.println(getCount1(arr, x, y, sx, sy, t));
    }

    private static int getCount1(int[][] arr, int x, int y, int sx, int sy, int t) {
        int h = arr.length;
        int w = arr[0].length;
        int count = 0; //计算1的个数
        if (arr[y][x]==1) count++;
        while (t > 0) {

             x = x + sx;
            int currentX= x;
             y = y + sy;
            int currentY= y;
            if (arr[currentY][currentX]==1){
                count++;
            }
            //遇到边界需要调转方向。
            //上边界或者下边界
            if (currentY == 0 || currentY == h - 1) {
                //速度x方向不变，y变为相反数
                sx = sx;
                sy = -sy;
            }
            //左边界或者右边界，速度y方向不变，x变为相反数
            else if (currentX == 0 || currentX == w - 1) {
                sx = -sx;
                sy = sy;
            }
            t--;
        }
        return count;
    }
}
